﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace likou
{
    //2024年7月2日22:55:41
    //力扣3115

    [TestClass]
    public class July02
    {

        [TestMethod]
        public void TestMethod1()
        {
            //int test[] = [4, 2, 9, 5, 3];
            int[] myNum = { 4, 2, 9, 5, 3 };
            //int res = 3;
           int res =  MaximumPrimeDifference(myNum);
            Console.WriteLine(res);
        }

        public int MaximumPrimeDifference(int[] nums)
        {
            int n = nums.Length;
            int result = 0;
            for(int left = 0,right = n-1;left<= right;)
            {
                bool a = IsPrimeNumberByClassic(nums[left]);
                bool b = IsPrimeNumberByClassic(nums[right]);
                if (a && b)
                {
                    return right-left;
                }
                if(!a) left++;
                if (!b) right--;
            }
            return result;
        }

        bool IsPrimeNumberByClassic(int item)
        {
            if (item == 1) return false;
            for(int i = 2;i*i <= item; i++)
            {
                if (item % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
    }




}
